-- ***********************************************
-- * Inspiration
-- ***********************************************
--------
function special_inspiration()

	local target = Attack.get_target()
	Attack.aseq_rotate(0, target, "cast")
	local dmgt = Attack.aseq_time(0, "x")

	Attack.atom_spawn(target, dmgt, "effect_encouragement", Attack.angleto(target))
	Attack.act_charge(target,0)

	if Attack.act_is_spell(target, "spell_magic_bondage")
	or Attack.act_is_spell(target, "special_stupid") then

		Attack.act_del_spell(target, "spell_magic_bondage")
		Attack.act_del_spell(target, "special_stupid")

		if Attack.act_size(target)>1 then

			Attack.log(0.001,"add_blog_magic_bondage_remove", "name","    "..blog_side_unit(target,0))
		end
	end

	if Attack.act_size(target)>1 then

		Attack.log(0.001,"add_blog_recharge", "name","    "..blog_side_unit(target,0))
	end

	return true
end
--------
-- ***********************************************
-- * Meteorite Fall
-- ***********************************************
--------
function special_meteorite_fall()

	local target = Attack.get_target()
	Attack.aseq_rotate(0, target, "cast")
	local dmgt = Attack.aseq_time(0, "x")
	local dmgt1,dmgt2,dmgt3,dmgt4=0,0,0,0
	if (target ~= nil) then

		local a = Attack.atom_spawn(target, dmgt, "effect_meteorite_fall")
		dmgt1 = Attack.aseq_time(a, "x")
		local b = Attack.atom_spawn(target, dmgt+dmgt1+.3, "effect_meteorite_fall_hit" )
		dmgt2 = Attack.aseq_time(b, "x")

		local duration = Attack.get_custom_param("duration")
		local dmg_min,dmg_max = text_range_dec(Attack.get_custom_param("damage"))
		local typedmg=Attack.get_custom_param("typedmg")

		if not (Attack.act_feature(target,"plant,golem,mech,undead,pawn,boss")
		or Attack.act_name(target)=="griffin_spirit")
		and Game.CurLocRand(1,100) <50 then

			effect_paralysis_attack(target,dmgt+dmgt1+dmgt2+.3,duration,false)

			if Attack.act_size(target)>1 then

				Attack.log(0.001,"add_blog_paralysis", "name","    "..blog_side_unit(target,0))
			end
		end

		if not Attack.act_feature(target,"pawn,boss") then

			local caster_lead=tonumber(Attack.act_leadership(0))*tonumber(Attack.act_size(0))
			local target_lead=tonumber(Attack.act_leadership(target))*tonumber(Attack.act_size(target))
			local caster_size=tonumber(Attack.act_size(0))
			local target_totalhp=tonumber(Attack.act_totalhp(target))

			if (caster_lead/2)>target_lead
			and Game.CurLocRand(1,100)<25 then

				Attack.atk_set_damage(typedmg,(target_totalhp+10)/caster_size)
			else
				Attack.atk_set_damage(typedmg,dmg_min*1.5,dmg_max*1.5)
			end
		else
			Attack.atk_set_damage(typedmg,dmg_min*1.5,dmg_max*1.5)
		end

		common_cell_apply_damage(target,dmgt+dmgt1+dmgt2+.3)

		local n = Attack.cell_count()
		for j=0,n-1 do

			local i = Attack.cell_get(j)
			if Attack.cell_dist(target,i) == 1 then

				local c = Attack.atom_spawn(i, dmgt+dmgt1+.3, "effect_meteorite_fall_hit2")
				dmgt3 = Attack.aseq_time(c, "x")

				if not (Attack.act_feature(i,"plant,golem,mech,undead,pawn,boss")
				or Attack.act_name(i)=="griffin_spirit")
				and Game.CurLocRand(1,100) <40 then

					effect_paralysis_attack(i,dmgt+dmgt1+dmgt2+.3,duration,false)

					if Attack.act_size(i)>1 then

						Attack.log(0.001,"add_blog_paralysis", "name","    "..blog_side_unit(i,0))
					end
				end

				Attack.atk_set_damage(typedmg,dmg_min,dmg_max)
				common_cell_apply_damage(i,dmgt+dmgt1+dmgt3+.3)

			elseif Attack.cell_dist(target,i) == 2 then

				local d = Attack.atom_spawn(i, dmgt+dmgt1+.3, "effect_meteorite_fall_hit3" )
				dmgt4 = Attack.aseq_time(d, "x")

				if not (Attack.act_feature(i,"plant,golem,mech,undead,pawn,boss")
				or Attack.act_name(i)=="griffin_spirit")
				and Game.CurLocRand(1,100) <20 then

					effect_paralysis_attack(i,dmgt+dmgt1+dmgt2+.3,duration,false)

					if Attack.act_size(i)>1 then

						Attack.log(0.001,"add_blog_paralysis", "name","    "..blog_side_unit(i,0))
					end
				end

				Attack.atk_set_damage(typedmg,dmg_min*.5,dmg_max*.5)
				common_cell_apply_damage(i,dmgt+dmgt1+dmgt2+.3)
			end
		end
	end
	return true
end

function effect_paralysis1_attack(target,pause,duration,dod)

	if pause==nil then
		pause = 1
	end
	if duration==nil then
		duration = tonumber(Logic.obj_par("effect_paralysis1","duration"))
	end
	if dod==nil then
		dod = true
	end
	if target~=nil then
		if (Attack.act_ally(target) or Attack.act_enemy(target)) and not Attack.act_feature(target,"boss,pawn") then
			Attack.act_apply_spell_begin( target, "effect_paralysis1", duration, dod)
			Attack.act_skipmove(target,duration)
			Attack.act_apply_spell_end()
		end
	end
	return true
end

function calccells_meteorite_fall()
	local n = 19
	Attack.multiselect(n)

	local c = Attack.cell_count()
	for i=0,c-1 do

		local cell = Attack.cell_get(i)

		if Attack.cell_is_pass(cell) or Attack.get_caa(cell) ~= nil then

			Attack.marktarget(cell, false)
		end
	end
	return true
end
--------
-- ***********************************************
-- * Fire Cyclone1
-- ***********************************************
--------
function special_fire_cyclone1()

	local target = Attack.get_target()
	Attack.aseq_rotate(0, target, "cast")
	local dmgt = Attack.aseq_time(0, "x")
	local dmgt1,dmgt2=0,0
	if (target ~= nil) then

		local a = Attack.atom_spawn(target, dmgt-.5, "effect_fire_cyclone", Attack.angleto(target))
		local dmgt1 = Attack.aseq_time(a, "x")

		local n = Attack.cell_count()
		for j=0,n-1 do

			local i = Attack.cell_get(j)
			if Attack.cell_dist(target,i) <=1 then

				local typedmg=Attack.get_custom_param("typedmg")
				local dmg_min,dmg_max = text_range_dec(Attack.get_custom_param("damage"))
				local pain_count = tonumber(Attack.act_initsize(0) - Attack.act_size(0))
				local dmg_min_pain = tonumber(dmg_min*pain_count*4/Attack.act_size(0))
				local dmg_max_pain = tonumber(dmg_max*pain_count*4/Attack.act_size(0))

				if (Attack.act_ally(i)
				or Attack.act_enemy(i)
				or Attack.act_feature(i,"pawn")) then

					local b = Attack.atom_spawn(i, dmgt+.6, "effect_fire_torch")
					dmgt2 = Attack.aseq_time(b, "x")
				end

				if Attack.act_is_spell(i, "effect_burn") then

					Attack.act_del_spell(i, "effect_burn")
					Attack.atk_set_damage(typedmg,(dmg_min+dmg_min_pain)*1.5,(dmg_max+dmg_max_pain)*1.5)
				else
					Attack.atk_set_damage(typedmg,dmg_min+dmg_min_pain,dmg_max+dmg_max_pain)
				end

				common_cell_apply_damage(i, dmgt+dmgt1+dmgt2)
			end
		end
	end
	return true
end
--------